<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>查看所有账户</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
        }
        .container {
            width: 80%;
            margin: 50px auto;
            padding: 20px;
            background: #fff;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
        h2 {
            text-align: center;
            color: #333;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        th, td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }
        th {
            background-color: #f2f2f2;
        }
        tr:hover {
            background-color: #f5f5f5;
        }
    </style>
</head>
<body>
<div class="container">
    <h2>所有账户信息</h2>
    <table id="usersTable">
        <thead>
        <tr>
            <th>ID</th>
            <th>用户名</th>
            <th>密码</th>
            <th>验证码</th>
        </tr>
        </thead>
        <tbody>
        <!-- 用户数据将在这里动态插入 -->
        </tbody>
    </table>
</div>

<script>
    // 获取所有用户数据
    function fetchUsers() {
        fetch('http://localhost:8081/waste/api/selectAllUsers')
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    const users = data.data;
                    const tableBody = document.querySelector('#usersTable tbody');
                    tableBody.innerHTML = ''; // 清空表格内容

                    users.forEach(user => {
                        const row = document.createElement('tr');
                        row.innerHTML = `
                                <td>${user.id}</td>
                                <td>${user.username}</td>
                                <td>${user.password}</td>
                                <td>${user.captcha}</td>
                            `;
                        tableBody.appendChild(row);
                    });
                } else {
                    alert('获取用户数据失败！');
                }
            })
            .catch(error => {
                alert('获取用户数据失败，请检查网络连接！');
                console.error('Error:', error);
            });
    }

    // 页面加载时调用
    window.onload = fetchUsers;
</script>
</body>
</html>